package cn.ant0n.cpm;

public class Resource {


    private final int maxSize = 5;
    private int currSize;


    public Resource() {
        this.currSize = 0;
    }


    public synchronized void remove(){
        if(currSize == 0){
            try {
                wait();
            }catch (InterruptedException e){
                throw new RuntimeException(e);
            }
        }
        currSize--;
        System.out.println("消费了一个，目前个数为:" + currSize);
        notify();
    }

    public synchronized void put(){
        if(currSize == maxSize){
            try {
                wait();
            }catch (InterruptedException e){
                throw new RuntimeException(e);
            }
        }
        currSize++;
        System.out.println("生产了一个，目前个数为:" + currSize);
        notify();
    }
}
